#!/usr/local/bin/perl

#
# Prologue.
#

use iSOCK::Test::Prelude;

BEGIN {
  use iSOCK::Test::Setup;
  
  iSOCK::Test::Setup->setup;
}

#
# Modules.
#

use SOCK::TDD;
use Test::WWW::Mechanize::Catalyst qw( iSOCK );
use Test::Differences;

#
# Plan.
#

my $tdd = SOCK::TDD->new ({ tests => 8 });
my $tmp = $tdd->tmp;

#
# Variables.
#

my $t38_path = "$ENV{PWD}/root/SOCK/t/038-spirit_to_whatever";

#
# Mech.
#

my $mech = Test::WWW::Mechanize::Catalyst->new;

$mech->timeout ( $mech->timeout * 2 );

#
# Login.
#

iSOCK::Test::Setup->login ( $mech );

#
# Product.
#

$mech->title_is ( 'iSOCK Specification::Process' );

for my $path ( grep { -d } glob "$t38_path/*" ) {
  my ( $product ) = ( $path =~ /(\w+)$/ );
  
  next if $product ne 'AT91SAM9M11';
  
  #
  # Process.
  #
  
  $mech->select ( svn_product => 'SAM9M11' );
  
  $mech->untick ( do_svn_mif_file => 'yes' );
  
  $mech->field ( re_include => 'AC97C' );
  
  $mech->select ( datasheets_source => 'Subversion (tags)' );
  $mech->tick ( $_ => 'yes' ) for qw( do_mifs do_spirits );
    
  $tdd->echo ( "$tmp/11-isock_process.html", $mech->content );
  
  $mech->click;
  
  #
  # Status.
  #
  
  $tdd->echo ( "$tmp/11-isock_status.html", $mech->content );
  
  $mech->title_is ( 'iSOCK Specification::Status' );
  
  $mech->content_contains ( $_ ) for qw( AC97C OK subversion );
  
 #$mech->content_lacks ( 'KO' ); # FIXME understand why it is now broken
  
  $mech->follow_link ( text => 'Download' );
  
  #
  # Download.
  #
  
  $tdd->echo ( "$tmp/11-isock_download.html", $mech->content );
  
  $mech->title_is ( 'iSOCK Specification::Download' );
  
 #$mech->page_links_ok; # triggers << Deep recursion on subroutine "Test::WWW::Mechanize::Catalyst::_make_request" >>
}
